package cn.tradewin.pmp.services.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import cn.tradewin.pmp.persist.client.MDeptMapper;
import cn.tradewin.pmp.persist.client.MEmpMapper;
import cn.tradewin.pmp.persist.model.MEmp;
import cn.tradewin.pmp.services.EmpManageService;

public class EmpManageServiceImpl implements EmpManageService {

	private final SqlSessionFactory sqlSessionFactory;

	public EmpManageServiceImpl(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionFactory = sqlSessionFactory;
	}

	@Override
	public int AddEmp(MEmp emp) {
		SqlSession session = null;
		try {
			session = sqlSessionFactory.openSession();
			MEmpMapper mapper = session.getMapper(MEmpMapper.class);
			int iCount = mapper.insert(emp);
			if (iCount > 0) {
				session.commit();
			}
			return iCount;
		} catch (Exception e) {
			session.rollback();
			throw new RuntimeException(e.getMessage());
		}
	}

	@Override
	public int updEmp(MEmp emp) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int DelEmps(List<String> emps) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<MEmp> getAllEmps() {
		SqlSession session = null;
		try {
			session = sqlSessionFactory.openSession();
			MEmpMapper mapper = session.getMapper(MEmpMapper.class);
			return mapper.selectByExample(null);
		} catch (Exception e) {
			session.rollback();
			throw new RuntimeException(e.getMessage());
		}
	}

	@Override
	public MEmp findEmpByPrimary(String empNo) {
		// TODO Auto-generated method stub
		return null;
	}

}
